package com.ipzoe.common.repository;

import com.ipzoe.common.bean.entity.Admin;
import com.ipzoe.common.util.DefaultMapper;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 后台管理员repository
 * <p>
 * Created on 2018/1/18.
 *
 * @author pfzhang
 */
@Mapper
public interface AdminRepository extends DefaultMapper<Admin> {

    /**
     * 根据用户名查询管理员对象
     *
     * @param username 用户名
     * @return 管理员对象
     */
    @Select("select * from admin where binary username = #{0} and del_flag = 0")
    @Results({
            @Result(column = "role_id", property = "roleId"),
            @Result(column = "role_id", property = "role",
                    one = @One(select = "com.ipzoe.yueya.repository.RoleRepository.selectByPrimaryKey"))
    })
    Admin findByUsername(String username);

    /**
     * 根据关键字查询管理员集合
     *
     * @param key 关键字
     * @return 管理员集合
     */
    @Select("select * from admin where username like #{0} and del_flag = 0 and id <> 1 order by create_time desc")
    @Results({
            @Result(column = "role_id", property = "roleId"),
            @Result(column = "role_id", property = "role",
                    one = @One(select = "com.ipzoe.common.repository.RoleRepository.selectByPrimaryKey"))
    })
    List<Admin> search(String key);
}
